# Contributor: Bart Ribbers <bribbers@disroot.org>
# Maintainer: Bart Ribbers <bribbers@disroot.org>
pkgname=kdsoap
pkgver=2.1.1
pkgrel=4
pkgdesc="Additional components to increase the functionality of KIO"
# armhf blocked by extra-cmake-modules
arch="all !armhf"
url="https://www.kdab.com/development-resources/qt-tools/kd-soap/"
license="LGPL-2.1-only AND LGPL-3.0-only AND (GPL-2.0-only OR GPL-3.0-only) AND AGPL-3.0-only"
depends_dev="qt5-qtbase-dev"
makedepends="
	cmake
	doxygen
	qt5-qtbase-dev
	qt6-qtbase-dev
	samurai
	"
source="https://github.com/KDAB/KDSoap/releases/download/kdsoap-$pkgver/kdsoap-$pkgver.tar.gz"
subpackages="$pkgname-qt6-dev:qt6_dev $pkgname-dev $pkgname-doc $pkgname-qt6 $pkgname-qt5"

build() {
	cmake -B build-qt5 -G Ninja \
		-DCMAKE_BUILD_TYPE=MinSizeRel \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_LIBDIR=lib \
		-DKDSoap_TESTS=true \
		-DKDSoap_EXAMPLES=false \
		-DKDSoap_QT6=false
	cmake -B build-qt6 -G Ninja \
		-DCMAKE_BUILD_TYPE=MinSizeRel \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_LIBDIR=lib \
		-DKDSoap_TESTS=true \
		-DKDSoap_EXAMPLES=false \
		-DKDSoap_QT6=true

	cmake --build build-qt5
	cmake --build build-qt6
}

check() {
	# kdsoap-webcalls, kdsoap-webcalls_wsdl and kdsoap-test_calc require network access
	# kdsoap-test_wsdl_document is broken on s390x, https://github.com/KDAB/KDSoap/issues/245
	local skipped_tests="kdsoap-("
	local tests="
		webcalls
		webcalls_wsdl
		test_calc
		"
	[ "$CARCH" = "s390x" ] && tests="$tests test_wsdl_document"
	for test in $tests; do
		skipped_tests="$skipped_tests|$test"
	done
	skipped_tests="$skipped_tests)"
	ctest --test-dir build-qt5 --output-on-failure -E "$skipped_tests"
	ctest --test-dir build-qt6 --output-on-failure -E "$skipped_tests"
}

package() {
	DESTDIR="$pkgdir" cmake --install build-qt5
	DESTDIR="$pkgdir" cmake --install build-qt6
}

qt5() {
	amove usr/lib
}

qt6() {
	amove usr/lib/*qt6*
}

dev() {
	default_dev

	amove usr/bin/kdwsdl2cpp
	amove usr/share/mkspecs

	rm -r "$subpkgdir"/usr/lib/*qt6*
}

qt6_dev() {
	depends="!$pkgname-dev qt6-qtbase-dev"

	DESTDIR="$subpkgdir" cmake --install "$builddir"/build-qt6
	rm "$subpkgdir"/usr/lib/libkdsoap-qt6.so.*
	rm "$subpkgdir"/usr/lib/libkdsoap-server-qt6.so.*
	rm -r "$subpkgdir"/usr/share/doc
}

sha512sums="
12224f664dcae7ceb7395a7c3de48a208ae81c10f6fba4d0db233613472c6b9cdbea6375297c27b58fe7338d7db27a4447844f4e8f40a24ec1b4dd3fa38d20bb  kdsoap-2.1.1.tar.gz
"
